USE [HomestayWebDB]
GO
/****** Object:  StoredProcedure [dbo].[Store_Comment_GetCommentsOfPost]    Script Date: 11/26/2012 17:15:38 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[Store_Comment_GetCommentsOfPost]    
 @PostID int  
AS    
BEGIN    
 -- SET NOCOUNT ON added to prevent extra result sets from    
 -- interfering with SELECT statements.    
 SET NOCOUNT ON;    
 SELECT  Comments.CommentID    
   ,Comments.Content    
   ,REPLACE(CONVERT(varchar, Comments.TimeCreated, 100), '.', '-') as TimeCreated    
   ,Users.Username  
   ,Comments.[Row]  
 FROM (SELECT ROW_NUMBER() OVER (ORDER BY PostID DESC)AS [Row],* FROM Comments  WHERE Comments.PostID = @PostID )AS Comments    
  LEFT JOIN Users ON (Users.Username = Comments.Username)    
 WHERE Users.IsDeleted = CAST(0 AS BIT)    
 ORDER BY Comments.TimeCreated DESC    
END 
